import Vue from 'vue'
import Router from 'vue-router'
import Admin from '@/components/Admin'
// 角色相关
import Role from '@/components/Role'
import Editrole from '@/components/Role/editRole'
import Addrole from '@/components/Role/addRole'
// 用户相关
import User from '@/components/User'
import Edituser from '@/components/User/editUser'
import Adduser from '@/components/User/addUser'
// 实验相关
import Experiment from '@/components/Experiment'
import Editexperiment from '@/components/Experiment/editExperiment'
import Addrecord from '@/components/Experiment/addRecord'
import Editrecord from '@/components/Experiment/editRecord'
// 设备相关
import Equipment from '@/components/Equipment'
import Editequipment from '@/components/Equipment/editEquipment'
import Addequipment from '@/components/Equipment/addEquipment'
// 材料相关
import Material from '@/components/Material'
import Editmaterial from '@/components/Material/editMaterial'
import Addmaterial from '@/components/Material/addMaterial'
//登录相关
import Login from '@/components/Login'


//路由跳转到和当前路径相同的页面发生报错,有问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

export default new Router({
    mode: 'history',
    routes: [{
            path: '/',
            redirect: '/login'
        },
        {
            path: '/login',
            name: 'Login',
            component: Login
        },
        {
            path: '/admin',
            name: 'Admin',
            component: Admin,
            // redirect: '/admin/role',
            children: [{
                    path: "role",
                    name: "Role",
                    component: Role
                }, {
                    path: "editrole",
                    name: "Editrole",
                    component: Editrole
                }, {
                    path: "addrole",
                    name: "Addrole",
                    component: Addrole
                }, {
                    path: "user",
                    name: "User",
                    component: User
                }, {
                    path: "edituser",
                    name: "Edituser",
                    component: Edituser
                }, {
                    path: "adduser",
                    name: "Adduser",
                    component: Adduser
                }, {
                    path: "experiment",
                    name: "Experiment",
                    component: Experiment
                }, {
                    path: "editexperiment",
                    name: "Editexperiment",
                    component: Editexperiment
                }, {
                    path: "addrecord",
                    name: "Addrecord",
                    component: Addrecord
                },
                {
                    path: "editrecord",
                    name: "Editrecord",
                    component: Editrecord
                },
                {
                    path: "equipment",
                    name: "Equipment",
                    component: Equipment
                }, {
                    path: "addequipment",
                    name: "Addequipment",
                    component: Addequipment
                }, {
                    path: "editequipment",
                    name: "Editequipment",
                    component: Editequipment
                }, {
                    path: "material",
                    name: "Material",
                    component: Material
                }, {
                    path: "addmaterial",
                    name: "Addmaterial",
                    component: Addmaterial
                }, {
                    path: "editmaterial",
                    name: "Editmaterial",
                    component: Editmaterial
                }
            ]
        }
    ]
})